import {AttackAudio} from "./const.ts";

export function init() {
    window.onkeyup = (e: KeyboardEvent) => {
        try {
            const keyMap = {
                d: {alert: "right", direction: "right"},
                a: {alert: "left", direction: "left"},
                w: {alert: "top", direction: "top"},
                s: {alert: "bottom", direction: "bottom"},
                j: {action: "fire"}
            } as { [key: string]: any };
            const action = keyMap[e.key];
            if (action) {
                if (action.alert) {
                } else if (action.action === "fire") {
                    if (!AttackAudio.paused) {
                        AttackAudio.currentTime = 0; // 重置音频播放时间
                    }
                    AttackAudio.play();
                }
            }
        } catch (error) {
            console.error('Error in main.onkeydown:', error);
        }
    }
}